package com.internetCafes.spms.web.tenant.controller;

import java.util.HashMap;
import java.util.Map;

import com.internetCafes.spms.core.annotation.SysLog;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.internetCafes.spms.core.model.pageModel.DataGrid;

import com.internetCafes.spms.web.tenant.model.TenantRoleInfo;
import com.internetCafes.spms.web.tenant.service.TenantRoleInfoService;
import com.internetCafes.spms.core.utils.Query;
import com.internetCafes.spms.core.utils.R;

import javax.servlet.http.HttpServletRequest;




/**
 * 租户角色信息
 * 
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2019-10-31 18:09:54
 */
@RestController
@RequestMapping("/tenant/tenantRoleInfo")
public class TenantRoleInfoController {

	@Autowired
	private TenantRoleInfoService tenantRoleInfoService;



	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("tenant:tenantRoleInfo:list")
	public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){

        //查询列表数据
        Query query = new Query(params);
        params = new HashMap<>();
        String tenantId = request.getParameter("tenantId");
        if(StringUtils.isNotBlank(tenantId)){
        	params.put("tenantId", Long.parseLong(tenantId));
		}

        DataGrid dataGrid = tenantRoleInfoService.dataGrid(params, query.getPage(), query.getLimit());

        return R.ok().put("page", dataGrid);
	}


	
	/**
	 * 根据ID获取数据
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("tenant:tenantRoleInfo:info")
	public R info(@PathVariable("id") Long id){
		TenantRoleInfo tenantRoleInfo = tenantRoleInfoService.findById(id);
		return R.ok().put("tenantRoleInfo", tenantRoleInfo);
	}



	/**
	 * 保存
	 */
	@SysLog("保存租户角色信息")
	@RequestMapping("/save")
	@RequiresPermissions("tenant:tenantRoleInfo:save")
	public R save(@RequestBody TenantRoleInfo tenantRoleInfo){
		tenantRoleInfoService.save(tenantRoleInfo);
		return R.ok();
	}



	/**
	 * 修改
	 */
	@SysLog("修改租户角色信息")
	@RequestMapping("/update")
	@RequiresPermissions("tenant:tenantRoleInfo:update")
	public R update(@RequestBody TenantRoleInfo tenantRoleInfo){
		tenantRoleInfoService.update(tenantRoleInfo);
		return R.ok();
	}



	/**
	 * 删除
	 */
	@SysLog("删除租户角色信息")
	@RequestMapping("/delete")
	@RequiresPermissions("tenant:tenantRoleInfo:delete")
	public R delete(@RequestBody Long[] ids){
		tenantRoleInfoService.deleteBatch(ids);
		return R.ok();
	}
	
}
